use log::info;

macro_rules! variable_utils {
    // 交换两个变量
    (swap $a:ident, $b:ident) => {
        std::mem::swap(&mut $a, &mut $b);
        info!("交换: {} <-> {}", stringify!($a), stringify!($b));
    };

    // 多个变量赋值
    (multi_assign ($($var:ident),*) = ($($val:expr),*)) => {
        $(
            let $var = $val;
        )*
        info!("多重赋值: {} = {}", stringify!($($var),*), stringify!($($val),*));
    };

    // 变量跟踪
    (trace $var:ident) => {
        info!("[TRACE] {} = {:?} (类型: {})",
            stringify!($var),
            $var,
            std::any::type_name_of_val(&$var));
    };
}

#[test]
fn marco_test() {
    let mut x = 10;
    let mut y = 20;

    variable_utils!(swap x, y);
    info!("x = {}, y = {}", x, y);

    variable_utils!(multi_assign (a, b, c) = (1, "hello", true));
    variable_utils!(trace a);
    variable_utils!(trace b);
}

#[derive(Debug)]
pub struct Demo {
    x: i32,
    y: String,
}

#[test]
fn demo_test() {
    let mut dx = Demo {x: 1, y: "adsa".to_string()};
    let mut dy = Demo {x: 2, y: "world".to_string()};

    variable_utils!(swap dx, dy);
    info!("dx: {:?}, dy: {:?}", dx, dy);
}